import { createRouter, createWebHashHistory } from 'vue-router'
// import Home from '../views/Home.vue'
import Home from '../components/Home.vue'
import Trate from '../components/trate/list.vue'
import Attence from '../components/attence/list.vue'
import Classperiod from '../components/classperiod/list.vue'
import Coures from '../components/coures/list.vue'
import Xuename from '../components/xuename/list.vue'
import Classroom from '../components/classroom/list.vue'
import Index from '../components/index.vue'
import Teacher from '../components/teacher/list.vue'
import Account from '../components/account/list.vue'
import Carouselfigure from '../components/carouselfigure/list.vue'
import Dynamic from '../components/dynamic/list.vue'
import Contact from '../components/contact/list.vue'
import Campus from '../components/campus/list.vue'
import Attendance from '../components/attendance/list.vue'
// import Select from '@/components/select'
// import Login from '../components/Login.vue'
// import Ch from '../components/ch.vue'
const routes = [
  // {
  //   path: '/select',
  //   name: 'select',
  //   component:Select
    
  // },
  {
    path:"/home",
    name:"Home",
    component:Home,
    redirect:"index",
    children:[
      {path:'/attence',component:Attence},
      {path:'/classperiod',component:Classperiod},
      {path:'/coures',component:Coures},
      {path:'/trate',component:Trate},
      {path:'/xuename',component:Xuename},
      {path:'/classroom',component:Classroom},
      {path:'/index',component:Index},
      {path:'/teacher',component:Teacher},
      {path:'/account',component:Account},
      {path:'/carouselfigure',component:Carouselfigure},
      {path:'/dynamic',component:Dynamic},
      {path:'/contact',component:Contact},
      {path:'/campus',component:Campus},
      {path:'/attendance',component:Attendance}
    ]
  },
  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import( '../components/Login.vue')
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})



// 路由守卫
router.beforeEach((to,from,next)=>{
   if(to.path=='/Login') return next()
   const token=sessionStorage.getItem('access_token')
   if(!token){
     return next('/Login')
   }
   next()
})

export default router
